package demo.web;

import demo.dao.impl.UserMapperImpl;
import demo.pojo.User;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.awt.print.Book;
import java.io.IOException;
import java.util.List;

public class UserSelectServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("json/application;charset=utf-8");
        response.getWriter().print(json());
    }

    static String json(){
        String data="{\"data\":[";
        String fh="";
        UserMapperImpl user1=new UserMapperImpl();
        List<User> list=user1.selectUser();
        for(User user:list){
            fh=",";
            data+=fh+"{\"id\":\""+user.getId()+"\",\"name\":\""+user.getName()+"\",\"password\":\""+user.getPassword()+"\"}";
        }
        data+="]}";
        return data;
    }
}
